package com.yixun.qfbao.hander;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yixun.qfbao.api.service.ThirdPartyApiService;
import com.yixun.qfbao.apidto.CreateQRCodeReqDto;
import com.yixun.qfbao.apidto.CreateQRCodeResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.vo.CreateQRCodeReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;

/**
 * （2）	生成微信二维码
 * 
 * @author jzliu
 *		
 */
@Service("createQRCodeHander")
public class CreateQRCodeHander extends CommonAbstractHander {
	private static Logger logger= LoggerFactory.getLogger(CreateQRCodeHander.class);
	
	@Autowired
	private ThirdPartyApiService thirdPartyApiService;
	
	@SuppressWarnings("rawtypes")
	@Override
	public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
		CreateQRCodeReqVo req = (CreateQRCodeReqVo)reqDto;
		CreateQRCodeReqDto reqDto1 = req.getParams();
		BaseResponseDTO<CreateQRCodeResDto> res = new BaseResponseDTO<CreateQRCodeResDto>();
		CreateQRCodeResDto resDto = new CreateQRCodeResDto();
		try {
			resDto = thirdPartyApiService.createQRCode(reqDto1);
			if(StringUtils.isNotBlank(resDto.getQrCode())){
				String code = resDto.getQrCode();
				code =  code.replaceAll("\n","");
				code = code.replaceAll("\r","");
				resDto.setQrCode(code);
			}
		} catch (Exception e) {
			logger.error("CreateQRCodeHander error: {}", e);
			resDto.setResult(ResultEnum.FAIL.getNo());
			resDto.setResultMsg("生成微信二维码失败!");
		}
		res.setResData(resDto);
		res.setResult(resDto.getResult());
		return res;
	}
	
}
